package inter.face.interface1;

/**
 * @author shkstart
 * @date 2022/6/8 - 18:02
 */
//  * 接口的应用：代理模式
//    与抽象类的  模板方法类似，把需要暴露的地方暴露出来
public class NetWorkTest {
    public static void main(String[] args) {
        Server server = new Server();
        ProxySever proxySever = new ProxySever(server);
        proxySever.browse();
    }
}

interface NetWork{
    public void browse();
}


//被代理类
class Server implements NetWork{

    @Override
    public void browse() {
        System.out.println("真实的服务器访问网络");
    }
}
//代理类
class ProxySever implements NetWork{
    private NetWork netWork;

    public ProxySever(NetWork netWork){
        this.netWork = netWork;
    }

    void check() {
        System.out.println("联网之前的检查工作");
    }
    @Override
    public void browse() {
        check();


        netWork.browse();

    }
}
